package src;

import java.awt.Color;

public class ColorHelper
{
	public static int		baseColor;
	private static boolean	lighten	= true;

	public static float[] RGB2HSV(Color color)
	{
		float[] hsbvals = new float[3];
		hsbvals = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
		
		return hsbvals;
	}
	
	public static int HSV2RGB(float[] hsv)
	{
		int color = Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]);
		
		return color;
	}
	
	public static int changeColor(int color)
	{
		if (lighten)
			return HSV2RGB(brigthen(RGB2HSV(new Color(color))));
		else
			return HSV2RGB(darken(RGB2HSV(new Color(color))));
	}
	
	public static float[] brigthen(float[] hsv)
	{
		float[] baseHSV = RGB2HSV(new Color(baseColor));
//		hsv[0] += 0.09;
		hsv[2] += 0.01;
		
		if (hsv[2] >= 0.98f)
			lighten = false;
		
		hsv[0] = baseHSV[0];
		hsv[1] = baseHSV[1];
		
		return hsv;
	}
	
	public static float[] darken(float[] hsv)
	{
		float[] baseHSV = RGB2HSV(new Color(baseColor));
//		hsv[0] -= 0.09;
		hsv[2] -= 0.01;
		
		if (hsv[2] <= 0.02f)
			lighten = true;
		
		hsv[0] = baseHSV[0];
		hsv[1] = baseHSV[1];
		
		return hsv;
	}
}
